#pragma once
#include <iostream>
#include <assert.h>
namespace Yzw
{
	template <class T>
	class vector
	{
	public:
		typedef T* iterator;
		typedef const T* const_iterator;

		vector()
		{
			_start = nullptr;
			_finish = nullptr;
			_end_of_stroage = nullptr;
		}

		size_t size()
		{
			return this->_finish - this->_start;
		}

		size_t capacity()
		{
			return this->_end_of_stroage - this->_start;
		}

		void reserve(size_t n)
		{
			if (n > capacity())
			{
				size_t old_size = size();
				T* tmp = new T[n];
				//memcpy(tmp, _start, old_size * sizeof(T));
				for (size_t i = 0; i < old_size; i++)
				{
					tmp[i] = _start[i];
				}
				delete[] _start;

				_start = tmp;
				_finish = tmp + old_size;
				_end_of_stroage = tmp + n;
			}
		}

		
		void push(const T& e)
		{
			if (this->_start == this->_finish)
			{
				reserve(this->capacity() == 0 ? 4 : 2 * this->capacity());
			}
			*_finish = e;
			++_finish;
		}


	private:
		iterator _start;
		iterator _finish;
		iterator _end_of_stroage;
	};
}




